#!/bin/sh

#
# Copyright (c) 2016-2016 novunda
#

echo "                                                                         "
echo "         __    __  .______    __    __       _______. __    __           "
echo "        |  |  |  | |   _  \  |  |  |  |     /       ||  |  |  |          "
echo "        |  |__|  | |  |_)  | |  |  |  |    |   (----'|  |__|  |          "
echo "        |   __   | |   ___/  |  |  |  |     \   \    |   __   |          "
echo "        |  |  |  | |  |      |   --   | .----)   |   |  |  |  |          "
echo "        |__|  |__| | _|       \______/  |_______/    |__|  |__|          "
echo "                                                                         "
echo "                                                                         "



cd "$(dirname "$0")"

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname "$PRG"`

# Only set HPUSH_HOME if not already set
[ -f "$HPUSH_HOME"/bin/hpush.sh ] || HPUSH_HOME=`cd "$PRGDIR/.." ; pwd`
export HPUSH_HOME

# Set JavaHome if it exists
if [ -f "${JAVA_HOME}/bin/java" ]; then
   JAVA=${JAVA_HOME}/bin/java
else
   JAVA=java
fi
export JAVA

LOG_FILE=$HPUSH_HOME/config/hpush-log.properties
HPUSH_PATH=$HPUSH_HOME/
#LOG_CONSOLE_LEVEL=info
#LOG_FILE_LEVEL=fine
JAVA_OPTS=-server -Xms10g  -Xmx10g -XX:NewSize=512m -XX:SurvivorRatio=6 -XX:+AlwaysPreTouch -XX:+UseG1GC -XX:MaxGCPauseMillis=2000 -XX:GCTimeRatio=4 -XX:InitiatingHeapOccupancyPercent=30 -XX:G1HeapRegionSize=8M -XX:ConcGCThreads=16 -XX:G1HeapWastePercent=10 -XX:+UseTLAB -XX:+ScavengeBeforeFullGC -XX:+DisableExplicitGC
JAVA_OPTS_SCRIPT="-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true"

$JAVA -server $JAVA_OPTS $JAVA_OPTS_SCRIPT -DIGNITE_NO_ASCII=false -Dlog4j.configuration="file:$LOG_FILE" -Dhpush.path="$HPUSH_PATH" -cp "$HPUSH_HOME/lib/*" com.parsechina.hpush.server.HPushServer

